package frame.options.simulation.create.embedding;

import java.util.List;

import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import model.algorithms.embedding.EmbeddingAlgorithm;

import com.nexes.wizard.WizardPanelDescriptor;

import frame.options.simulation.create.CreateSimulationWizard;
import frame.options.simulation.create.coordinated.CoordinatedDescriptor;
import frame.options.simulation.create.rounding.RoundingDescriptor;

public class EmbeddingDescriptor extends WizardPanelDescriptor implements ListSelectionListener
{
	public static final String IDENTIFIER = EmbeddingDescriptor.class.getSimpleName();
	
	private EmbeddingPanel embeddingPanel;
	public EmbeddingPanel getEmbeddingPanel(){ return this.embeddingPanel; }
	public void setEmbeddingPanel( EmbeddingPanel embeddingPanel ){ this.embeddingPanel = embeddingPanel; }
	
	public EmbeddingDescriptor( List< EmbeddingAlgorithm > embeddingAlgorithms )
    {
		this.setEmbeddingPanel( new EmbeddingPanel( embeddingAlgorithms ) );
		this.getEmbeddingPanel().addListeners( this );
		
		this.setPanelDescriptorIdentifier( EmbeddingDescriptor.IDENTIFIER );
		this.setPanelComponent( this.getEmbeddingPanel() );
    }
	
	@Override
	public Object getBackPanelDescriptor()
	{
		return CoordinatedDescriptor.IDENTIFIER;
	}
	
    @Override
	public Object getNextPanelDescriptor()
    {
    	return RoundingDescriptor.IDENTIFIER;
    }
    
    @Override
	public void aboutToDisplayPanel()
    {
    	this.getWizard().setNextFinishButtonEnabled( false );
    }
	
	@Override
	public void valueChanged( ListSelectionEvent listSelectionEvent )
	{
    	if( this.getEmbeddingPanel().isOnlyOneSelected() )
    	{
    		( (CreateSimulationWizard) this.getWizard() ).setEmbeddingAlgorithm( this.getEmbeddingPanel().getSelectedEmbeddingAlgorithm() );
    		this.getWizard().setNextFinishButtonEnabled( true );
    	}
    	else
    		this.getWizard().setNextFinishButtonEnabled( false );
	}

}
